package pers.elonnsu.springbootmall.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pers.elonnsu.springbootmall.common.ApiRestResponse;
import pers.elonnsu.springbootmall.model.pojo.Product;
import pers.elonnsu.springbootmall.model.request.ProductListReq;
import pers.elonnsu.springbootmall.service.ProductService;

@RestController
public class ProductController {
    @Autowired
    private ProductService productService;

    @ApiOperation("客户：获取商品列表")
    @GetMapping("/product/list")
    public ApiRestResponse<Object> list(ProductListReq productListReq) {
        PageInfo<Product> productPageInfo = productService.listForCustomer(productListReq);
        return ApiRestResponse.success(productPageInfo);
    }

    @ApiOperation("客户：获取商品详情")
    @GetMapping("/product/detail")
    public ApiRestResponse<Object> detail(@RequestParam("id") Integer id) {
        Product product = productService.detail(id);
        return ApiRestResponse.success(product);
    }
}
